package com.edu.alg;

import java.text.DecimalFormat;
import java.util.List;

import com.edu.dao.UserAndGameTableDao;
import com.edu.jdbc.DatabaseConnection;

public class GenerateSimilarMatrix {
	
	
	public double[][] generateSimilarMatrix(){
		double[][] similarMartix=new double[DatabaseConnection.N][DatabaseConnection.N];
		Similarity cs=new Similarity();
		UserAndGameTableDao uagtDao=new UserAndGameTableDao();
		List<Integer> AllUserList=uagtDao.findAllUser();
		double similarity;
		
		for(int i=0;i<DatabaseConnection.N;i++){
			for(int j=0;j<DatabaseConnection.N;j++){
				//System.out.println("i:"+i+",j:"+j);
				similarity=cs.calculate(AllUserList.get(i), AllUserList.get(j));
				similarMartix[i][j]=similarity;
			}
		}
		return similarMartix;
	}
	
	public void output(){
		double[][] display=generateSimilarMatrix();
		DecimalFormat df=new DecimalFormat("#.###");
		for(int i=0;i<DatabaseConnection.N;i++){
			for(int j=0;j<DatabaseConnection.N;j++){
				String st=df.format(display[i][j]);
				System.out.print(st+"\t");
			}
			System.out.println();
		}
	}
}
